﻿using FastCloud.Base.Desgin;
using FastCloud.ORG.Entity;
using FastORM.Entity;
using FastUtil.Data;
using System;
using System.Collections.Generic;
using System.Text;

namespace FastCloud.ORG.DB
{
    public class DB_UserJobSetting : BaseDBML<Frame_UserJob_Setting>
    {
        public override void Insert(Frame_UserJob_Setting Entity)
        {
            if (string.IsNullOrEmpty(Entity.SettingGuid))
            {
                Entity.SettingGuid = GenerateUtil.GenerateUnitGuid();
            }
            base.Insert(Entity);
        }

        public bool CheckExistUserJobSetting(string UserGuid)
        {
            return SelectCount("UserGuid=@UserGuid", new List<ParamEntity>() { new ParamEntity() { ParamName = "UserGuid", ParamValue = UserGuid } }) > 0;
        }

        public bool CheckExistUserJobSetting(string UserGuid,string DefaultUserJobGuid)
        {
            return SelectCount("UserGuid=@UserGuid and DefaultUserJobGuid=@DefaultUserJobGuid", new List<ParamEntity>() { new ParamEntity() { ParamName = "UserGuid", ParamValue = UserGuid }, new ParamEntity() { ParamName = "DefaultUserJobGuid", ParamValue = DefaultUserJobGuid } }) > 0;
        }

        public Frame_UserJob_Setting SelectOneByUserGuid(string UserGuid)
        {
            return base.SelectOne("*", "UserGuid", UserGuid);
        }

        public List<Frame_UserJob_Setting> SelectListByUserGuid(string UserGuid)
        {
            return SelectAllList("*", "UserGuid=@UserGuid", new List<ParamEntity>() { new ParamEntity() { ParamName = "UserGuid", ParamValue = UserGuid } },"");
        }

        public void DeleteByUserGuid(string UserGuid)
        {
            DeleteByFiled("UserGuid", UserGuid);
        }
    }
}
